package com.kaifamiao.www.demo.do0815;

import java.util.Set;
import java.util.TreeMap;

public class Demo03 {
    public static void main(String[] args) {
        TreeMap treeMap = new TreeMap();
        treeMap.put("a",1);
        treeMap.put("e",8);
        treeMap.put("c",5);
        treeMap.put("f",6);
        /**
         * 迭代
         * entrySet  key-value  集合
         * keySet  map 集合中所有键（key）的集合
         * values map  集合中所有值的集合
         */
        //values
//        Collection collection = treeMap.values();
//        Iterator iterator = collection.iterator();
//        while (iterator.hasNext()){
//            System.out.println(iterator.next());
//        }
//        for (Object obj : collection){
//            System.out.println(obj);
//        }

        //keySet
        Set set = treeMap.keySet();
//        Iterator iterator = set.iterator();
//        while (iterator.hasNext()){
//            System.out.println(iterator.next());
//        }
        for (Object key : set){
            System.out.println(key + "=" + treeMap.get(key));
        }

        //entrySet
//        Set set = treeMap.entrySet();
//        for (Object obj : set){
//            if (obj instanceof Map.Entry entry){
//                System.out.println(entry.getKey() + "=" + entry.getValue());
//            }
//        }
//        Iterator iterator = set.iterator();
//        while (iterator.hasNext()){
//            System.out.println(iterator.next());
//        }
    }
}
